﻿package org.cubeland.game.core.drawing 
{
	import org.papervision3d.view.layer.util.ViewportLayerSortMode;
	import flash.display.Sprite;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	
	/**
	 * CubeLand.org Game
	 * @author Duarte Peixinho
	 */
	public class DrawGame extends Sprite
	{
	
		private var _width:uint = 0;
		private var _height:uint = 0;
		
		protected var _viewport:Viewport3D;
		protected var _camera:Camera3D;
		protected var _render:BasicRenderEngine;
		protected var _scene:Scene3D;
		
		public function DrawGame(width:uint = 640, height:uint = 480 ) 
		{			
			_width = width;
			_height = height;		
		}
		
		protected function init():void {
			_viewport = new Viewport3D(_width, _height);
			// add viewport to stage
			addChild(_viewport);
			
			_camera = new Camera3D();
			_render = new BasicRenderEngine();
			_scene = new Scene3D();								
		}
		
		public function render():void {
			_viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;
			_render.renderScene(_scene, _camera, _viewport);
		}
		
		public function get viewport():Viewport3D {
			return _viewport;
		}
		
		public function set viewport(viewport:Viewport3D):void {
			_viewport = viewport;
		}
		
	}

}